package com.td.framework.webmanager.xtzd.action;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.td.framework.common.AbstractAction;
import com.td.framework.utils.ChineseTools;
import com.td.framework.webmanager.domain.AppsysDmb;
import com.td.framework.webmanager.domain.DMbean;
import com.td.framework.webmanager.page.PageService;

public class XtzdAction extends AbstractAction {
	//代码表实体对象
    private AppsysDmb  appsysDmb;
    //代码表对象集合
    private List<AppsysDmb> dmbList;
    //查询条件
    private String dmlx;//代码类型
    private List<DMbean> lxList;//类型集合
    private Log log = LogFactory.getLog(XtzdAction.class);
    
    /**
     * 代码表列表集合
     * @return
     */
    public String listDmb(){
    	String hql ="from AppsysDmb t";
    	if(dmlx!=null && !"".equals(dmlx)){
    	  hql+=" where t.dmlx='"+dmlx+"'";
    	}
    	int rows = this.getBaseService().getRowsByListHql(hql);				
		page = PageService.getPage(rows, currentPage, pageSize, pageMethod);
		this.setCurrentPage(page.getCurentPage());		
		this.setPageSize(page.getPageSize());
		dmbList =this.getBaseService().getPageList(hql,page.getStartRow(),pageSize);
		String sql = "select t.dmlxid,t.dmlxmc from appsys_dmlxb t";
		lxList = this.getBaseService().getDmbeansBySql(sql);
    	return SUCCESS;
    }
    
    /**
     * 打开代码表添加页面
     */
    public String createDmbForm(){
    	return SUCCESS;
    }
    
    /**
     * 添加代码表信息
     * @return
     */
    public String createDmb(){
	     boolean flag = false;
		try {
			String pyzt = ChineseTools.getFirstLetter(appsysDmb.getZwmc());
			appsysDmb.setPyzt(pyzt);
			flag = this.getBaseService().saveEntity(appsysDmb);
		} catch (Exception e) {
			 log.error("增加代码表失败："+e.getMessage());
			 this.handleMessage("info", "添加失败,联系管理员!");
		}
		if(flag = true){
	    	 this.handleMessage("info", "添加成功，请继续操作!");
	     }	     
	     return SUCCESS;
    }
    
    /**
     *打开修改页面 
     * @return
     */
    public String reworkDmbForm(){
    	appsysDmb = (AppsysDmb) this.getBaseService().getEntityById(AppsysDmb.class,zids[0]);
    	return SUCCESS;
    }
    
    /**
     * 修改代码表信息
     * @return
     */
    public String reworkDmb(){
    	 boolean flag = false;
 		try {
 			flag = this.getBaseService().saveOrUpdate(appsysDmb);
 		} catch (Exception e) {
 			log.error("修改代码表失败："+e.getMessage());
 			 this.handleMessage("info", "修改失败,请联系管理员!");
 		}
 	     if(flag = true){
 	    	 this.handleMessage("info", "添加成功!");
 	     }
 	     return SUCCESS; 
    }
    
    /**
     * 删除选中的信息
     * @return
     */
    public String removeDmb(){
    	 boolean flag = false;
  	     flag = this.getBaseService().deleteBatch(AppsysDmb.class, zids);
  	     return SUCCESS; 
    }
    
    /**
     *打开展现页面
     * @return
     */
    public String showDmb(){
    	appsysDmb = (AppsysDmb) this.getBaseService().getEntityById(AppsysDmb.class,zids[0]);
    	return SUCCESS;
    }
    
	public List<AppsysDmb> getDmbList() {
		return dmbList;
	}
	public void setDmbList(List<AppsysDmb> dmbList) {
		this.dmbList = dmbList;
	}

	public AppsysDmb getAppsysDmb() {
		return appsysDmb;
	}

	public void setAppsysDmb(AppsysDmb appsysDmb) {
		this.appsysDmb = appsysDmb;
	}

	public String getDmlx() {
		return dmlx;
	}

	public void setDmlx(String dmlx) {
		this.dmlx = dmlx;
	}

	public List<DMbean> getLxList() {
		return lxList;
	}

	public void setLxList(List<DMbean> lxList) {
		this.lxList = lxList;
	}
    
}
